package com.tianyadu.mmall.core.validate.code;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 验证码
 *
 * @author xueyj
 * @date 2019-11-05 22:36
 */
@Data
public class ValidateCode {

    /**
     * 验证码
     */
    private String code;

    /**
     * 过期时间
     */
    private LocalDateTime expireTime;

    /**
     * 构造图形验证码
     *
     * @param code     验证码
     * @param expireIn 过期描述
     */
    public ValidateCode(String code, int expireIn) {
        this.code = code;
        //  过期时间：当前时间+过期秒数
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    /**
     * 校验验证码是否过期，
     * 校验规则，当前时间是否在过期时间之前
     */
    public boolean isExpried() {
        return LocalDateTime.now().isAfter(expireTime);
    }
}